﻿using System;

namespace MinMaxAverageProductSumGeneric
{
    class MinMaxAverageProductSumGeneric
    {
        static T MinElement<T>(params T[] array) where T : IComparable<T>
        {
            T minElement = array[0];
            for (int index = 1, length = array.Length; index < length; index++)
            {
                if (minElement.CompareTo(array[index]) > 0)
                {
                    minElement = array[index];
                }
            }
            return minElement;
        }
        static T MaxElement<T>(params T[] array) where T : IComparable<T>
        {
            T maxElement = array[0];
            for (int index = 1, length = array.Length; index < length; index++)
            {
                if (maxElement.CompareTo(array[index]) < 0)
                {
                    maxElement = array[index];
                }
            }
            return maxElement;
        }
        static T Average<T>(params T[] array) where T : IComparable<T>
        {
            dynamic average = array[0];
            for (int index = 1, length = array.Length; index < length; index++)
            {
                average += array[index];
            }
            return average / array.Length;
        }
        static T Sum<T>(params T[] array) where T : IComparable<T>
        {
            dynamic sum = array[0];
            for (int index = 1, length = array.Length; index < length; index++)
            {
                sum += array[index];
            }
            return sum;
        }
        static T Product<T>(params T[] array) where T : IComparable<T>
        {
            dynamic product = array[0];
            for (int index = 1, length = array.Length; index < length; index++)
            {
                product *= array[index];
            }
            return product;
        }
        static void Main()
        {
            Console.WriteLine("MinElement: {0}", MinElement(1, 3, 5, 7));
            Console.WriteLine("MaxElement: {0}", MaxElement(1, 3, 5, 7));
            Console.WriteLine("Sum: {0}", Sum(1, 3, 5, 7));
            Console.WriteLine("Product: {0}", Product(1, 3, 5, 7));
            Console.WriteLine("Average: {0}", Average(1, 3, 5, 7));
        }
    }
}
